package com.itfreer.power.dao.role;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.ConstraintMode;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.springframework.beans.BeanUtils;

import com.itfreer.form.api.JdbcBaseEntity;
import com.itfreer.power.entity.role.RoleMapExtentJurisdictionEntity;

/**
 * 角色与地图范围权限关系实体类
 */
@Entity(name = "sso_role_jurisdiction_mapext")
@Table(indexes = { 
        @Index(name="sso_r_j_me_roleId", columnList="role_id"),
        @Index(name="sso_r_j_me_functionId", columnList="function_id") })
public class JdbcRoleMapExtentJurisdictionEntity implements JdbcBaseEntity<RoleMapExtentJurisdictionEntity>, Serializable {
	
	private static final long serialVersionUID = -2495777227638126143L;

	@Id
	@Column(name = "id", length = 50, nullable = false)
	private String id;
	
	/**
	 * 角色ID
	 */
	@Column(name = "role_id", length = 50, nullable = true)
	private String roleId;

	/**
	 * 功能ID
	 */
	@Column(name = "function_id", length = 50, nullable = true)
	private String functionId;
	
	@ManyToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
	@JoinColumn(name = "id", insertable=false, updatable=false,
		foreignKey = @ForeignKey(name = "none",value = ConstraintMode.NO_CONSTRAINT))
	private JdbcRoleEntity role;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	/**
	 * 角色ID
	 */
	public String getRoleId() {
		return roleId;
	}

	/**
	 * 角色ID
	 */
	public void setRoleId(String roleId) {
		this.roleId = roleId;
	}

	/**
	 * 功能ID
	 */
	public String getFunctionId() {
		return functionId;
	}

	/**
	 * 功能ID
	 */
	public void setFunctionId(String functionId) {
		this.functionId = functionId;
	}
	
	@Override
	public void from(RoleMapExtentJurisdictionEntity t) {
		BeanUtils.copyProperties(t, this);
	}

	@Override
	public RoleMapExtentJurisdictionEntity toEntity() {
		RoleMapExtentJurisdictionEntity toEntity = new RoleMapExtentJurisdictionEntity();
		BeanUtils.copyProperties(this, toEntity);
		return toEntity;
	}
}